/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { hvigor } from '../../../../index';

hvigor.getProject();
import { TaskDirectedAcyclicGraph } from '../../../../../src/base/internal/task/core/task-directed-acyclic-graph';
import { DefaultTaskContainer } from '../../../../../src/base/internal/task/core/default-task-container';
import { DefaultInternalTask } from '../../../../../src/base/internal/task/core/default-internal-task';
import { noop } from '../../../../../src/common/util/noop';
import { Project } from '../../../../../src/base/external/core/hvigor-core-node.js';
import { mockProjectFromResourcesPath } from '../../common/init-project';

const project: Project = mockProjectFromResourcesPath('common-test');

describe('test task container', () => {
  const dag = new TaskDirectedAcyclicGraph();
  const moduleName = 'module1';
  const taskContainer = new DefaultTaskContainer(moduleName, dag);
  const module = project.findModuleByName(moduleName)!;

  test('test add&&delete&&find...', () => {
    const task1 = new DefaultInternalTask(module, {
      name:'task1'
    }, noop);
    const task2 = new DefaultInternalTask(module, {
      name:'task2'
    }, noop);
    taskContainer.addTask(task1);
    taskContainer.addTask(task2);
    expect(taskContainer.findTask('task1')).toBeDefined();
    taskContainer.deleteTask('task2');
    expect(taskContainer.findTask('task2')).toBeUndefined();
  });

});
